package com.dzl.enterprise;

import com.alibaba.fastjson.JSONObject;
import com.dzl.base.controller.BaseController;
import com.dzl.enterprise.pojo.WelfareEnterpriseConfig;
import com.dzl.enterprise.service.WelfareEnterpriseConfigService;
import com.dzl.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 企业小程序独立部署管理(WelfareEnterprise)表控制层
 * @author liuguanjun
 * @since 2022-02-14 16:11:41
 */
@RestController
@RequestMapping("welfareEnterpriseConfig")
public class WelfareEnterpriseConfigController extends BaseController {


    @Autowired
    private WelfareEnterpriseConfigService service;


    /**
     * 根据企业id查询独立部署配置信息
     * @date 2022-02-14 16:14:00
     * @author liuguanjun
     * @param enterpriseId 企业id
     */
    @GetMapping("selectByEnterpriseId")
    public JsonResult<WelfareEnterpriseConfig> selectByEnterpriseId(@RequestParam("enterpriseId") Integer enterpriseId) {
        if(enterpriseId == null) {
            return JsonResult.paramErrWithMsg("企业id不能传空");
        }
        return JsonResult.success(service.getWelfareEnterpriseConfigByEnterpriseId(enterpriseId));
    }

    /**
     * 配置规则
     * @param param enterpriseId 企业id
     * @param param ruleConfig 配置规则： 0同步自营企业数据  1自行配置
     * @date 2022-02-14 16:14:00
     * @author liuguanjun
     */
    /*@PostMapping("setRuleConfig")
    public JsonResult<String> setRuleConfig(@RequestBody JSONObject param) {
        Integer ruleConfig = param.getInteger("ruleConfig");
        Integer enterpriseId = param.getInteger("enterpriseId");
        if(enterpriseId == null) {
            return JsonResult.paramErrWithMsg("企业id不能传空");
        }
        if(ruleConfig == null) {
            return JsonResult.paramErrWithMsg("请选择配置规则");
        }
        WelfareEnterpriseConfig welfareEnterpriseConfig = new WelfareEnterpriseConfig();
        welfareEnterpriseConfig.setEnterpriseId(enterpriseId);
        welfareEnterpriseConfig.setRuleConfig(ruleConfig);
        Integer count = service.saveWelfareEnterpriseConfig(welfareEnterpriseConfig);
        return count > 0 ? JsonResult.success("保存成功") : JsonResult.paramErrWithMsg("保存失败！");
    }*/

    /**
     * 小程序设置
     * @param welfareEnterpriseConfig 企业小程序独立部署配置数据对象
     * @date 2022-02-14 16:14:00
     * @author liuguanjun
     */
    @PostMapping("setAppletConfig")
    public JsonResult<String> setAppletConfig(@RequestBody WelfareEnterpriseConfig welfareEnterpriseConfig) {
        if(welfareEnterpriseConfig.getEnterpriseId() == null) {
            return JsonResult.paramErrWithMsg("企业id不能传空");
        }
       /* if(EmptyUtils.isEmpty(welfareEnterprise.getEnterpriseAbbreviation())) {
            return JsonResult.paramErrWithMsg("公司简称不能为空");
        }
        welfareEnterpriseConfig.setRuleConfig(null);*/
        Integer count = service.saveWelfareEnterpriseConfig(welfareEnterpriseConfig);
        return count > 0 ? JsonResult.success("保存成功") : JsonResult.paramErrWithMsg("保存失败！");
    }


}
